// 化肥  第五
$.ajax({
    type: "post",
    async: true, //异步执行
    url: "nydsj/hf.html",
    dataType: "json", //返回数据形式为json
    success: function (json) {

        var myChart = echarts.init(document.getElementById('main5'));
        option = {
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            series: []
        };
        $.each(json, function (i, item) {
            var newArray = {};
            var center = ['50%', '30%'];
            var emphasis = {};
            emphasis.shadowBlur = 10;
            emphasis.shadowOffsetX = 0;
            emphasis.shadowColor = "rgba(0, 0, 0, 0.5)";
            var itemStyle = {};
            itemStyle.emphasis = emphasis;

            newArray.name = "使用量";
            newArray.type = "pie";
            newArray.radius = "35%";
            newArray.center = center;
            newArray.data = [];
            newArray.itemStyle = itemStyle;
            option.series.push(newArray);

        });
        $.each(json, function (i, item) {

            for (var j = 0; j < option.series.length; j++) {
                var dataa = {};
                var color = "#" + Math.floor(Math.random() * 16777216).toString(16);
                var itemStyle = {};
                itemStyle.color = color;
                dataa.value = item.weight;
                dataa.name = item.category;
                dataa.itemStyle = itemStyle;
                option.series[j].data.push(dataa);
            }
        });
        myChart.setOption(option);
    },
    error: function (errorMsg) {
        alert("请求数据失败");
    }
});